package com.zdsoft.finance.meet.service.process;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.zdsoft.bpm.annotation.client.AutoJob;
import com.zdsoft.finance.meet.entity.MeetingProject;
import com.zdsoft.finance.meet.service.MeetingProjectService;
import com.zdsoft.finance.spi.meeting.dto.MeetingProjectStatus;
import com.zdsoft.framework.core.common.exception.AppException;
import com.zdsoft.framework.core.common.protocol.RPCRequest;
import com.zdsoft.framework.core.common.protocol.RPCResponse;
import com.zdsoft.framework.core.server.RPCAbstractService;

@Service
@AutoJob(label = "检查上会项目状态", resource = "zf.autojob.business.meetingProjectStatusCheck", checkJob = true)
public class MeetingProjectStatusCheck extends RPCAbstractService {

	@Autowired
	MeetingProjectService meetingProjectService;

	@Override
	@Transactional
	public RPCResponse remoteCall(RPCRequest request) throws AppException {
		RPCResponse response = new RPCResponse();
		// 获取工作流背包参数
		Map<String, Object> bpmVars = request.getBodys();
		String businessId = (String) bpmVars.get("businessId");

		// 通过流程业务id查找上会项目
		MeetingProject meetingProject = meetingProjectService.findByBusinessId(businessId);
		if (MeetingProjectStatus.MEET_PROJECT_STATE_TOACCR.value == meetingProject.getState()) {
			response.setStatus(RPCResponse.SUCCESS);
		} else {
			response.setStatus(RPCResponse.FAILURE);
		}
		return response;
	}

}
